package com.ckerchina.admin.ckadmin.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicUpdate;

import com.ckerchina.admin.ckadmin.domain.IdEntity.IdEntityAuto;

/**
 * 短信发送日志和状态报告对象
 */
@DynamicUpdate(true)
@Table(indexes = { @Index(name = "IDX_result", columnList = "result") })
@Entity
public class SmsLog extends IdEntityAuto {

	private static final long serialVersionUID = 1L;

	/** 短信发送渠道的userId */
	@Column(length = 50)
	private String channelName; 

	/** 手机号码 */
	@Column(length = 1200)
	private String mobiles;

	/** 短信内容 */
	@Column(length = 500)
	private String content;

	/** 返回的结果，用于查询状态报告 */
	@Column(length = 50)
	private String result;

	/** 短信发送状态报告 */
	@Column(length = 200)
	private String statusReport;

	/** 创建时间 */
	private Date createTime;

	/** 短信条数 */
	private Integer smscount;

	/** 接收时间 */
	private Date receiveTime;

	/**
	 * 计算短信条数
	 */
	public Integer computeSmsCount() {
		if (StringUtils.isNotBlank(this.mobiles)) {
			String[] mobileArray = this.mobiles.split("\\,");
			if (StringUtils.isBlank(content)) {
				return 0;
			}
			int length = content.length() + 5;
			if (length <= 70) {
				return mobileArray.length;
			} else {
				int num = length / 67;
				if (length % 67 > 0) {
					num = num + 1;
				}
				return mobileArray.length * num;
			}
		} else {
			return 0;
		}
	}

	public String getChannelName() {
		return channelName;
	}

	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}

	public String getMobiles() {
		return mobiles;
	}

	public void setMobiles(String mobiles) {
		this.mobiles = mobiles;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getStatusReport() {
		return statusReport;
	}

	public void setStatusReport(String statusReport) {
		this.statusReport = statusReport;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getSmscount() {
		return smscount;
	}

	public void setSmscount(Integer smscount) {
		this.smscount = smscount;
	}

	public Date getReceiveTime() {
		return receiveTime;
	}

	public void setReceiveTime(Date receiveTime) {
		this.receiveTime = receiveTime;
	}

}
